<template>
  <div class="supplier">
    <el-form
      ref="reffromDate"
      :inline="true"
      :model="supplier"
      label-width="110px"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item>
            <span slot="label">供应商ID：</span>
            <div>{{ supplier.id }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item>
            <span slot="label" style="color: #ff0000">供应商名称：</span>
            <div>{{ supplier.name }}</div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="typeId">
            <span slot="label" style="color: #ff0000">供应商类别：</span>
            <el-select v-model="supplier.typeId" placeholder="请选择" disabled>
              <el-option
                v-for="(item, index) in arr1"
                :key="index"
                :label="item.itemName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="gradeId">
            <span slot="label" style="color: #ff0000">合作等级：</span>
            <el-select v-model="supplier.gradeId" placeholder="请选择">
              <el-option
                v-for="(item, index) in arr2"
                :key="index"
                :label="item.itemName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item prop="code">
        <span slot="label" style="color: #ff0000">协作单位：</span>
        <div>{{ supplier.text }}</div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getDicsType } from "@/api/common.js";
import { queryListsByPid, QueryOneByid } from "@/api/GHnumber/supplier.js";
import { saveOrUpdate as saveOrUpdatecooplevel } from "@/api/GHnumber/cooplevel.js";
export default {
  data() {
    return {
      supplier: {
        id: "c4c257bf767d4c448803a8dceb932deb",
        name: "",
        typeId: "",
        gradeId: "",
        text: "",
      },
      arr1: [],
      arr2: [],
    };
  },
  created() {
    this.supplier.id = this.$route.query.id;
    getDicsType({ codes: "supplierType,Levelofcooperation" }).then((res) => {
      this.arr1 = res.data.supplierType.items;
      this.arr2 = res.data.Levelofcooperation.items;
    });
    QueryOneByid({ id: this.supplier.id }).then((res) => {
      this.supplier.name = res.data.name;
      this.supplier.typeId = res.data.typeId;
      this.supplier.gradeId = res.data.gradeId;
    });
    queryListsByPid({ supplierId: this.supplier.id }).then((res) => {
      let key = res.data.map((res) => {
        return res.name;
      });
      this.supplier.text = key.join("，");
    });
  },
  methods: {
    /*提交审批时业务数据触发*/
    sumbie() {
      let data = {
        supplierId: this.supplier.id,
        gradeId: this.supplier.gradeId,
        gradeName: this.$fromatTable(
          this.arr2,
          this.supplier.gradeId,
          "id",
          "itemName"
        ),
      };
      saveOrUpdatecooplevel(data).then(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.supplier {
  padding: 20px 100px;
}
</style>